package org.flik.client.main;

import org.flik.client.main.service.UserServiceAsync;
import org.flik.client.shared.CommonAsyncCallback;
import org.flik.server.dto.InitialData;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootLayoutPanel;

public class Main implements EntryPoint {

	private static Long loggedInUserId;

	private static String loggedInUserFullName;
	public static String getLoggedInUserFullName() {
		return loggedInUserFullName;
	}
	public static Long getLoggedInUserId() {
		return loggedInUserId;
	}

	@Override
	public void onModuleLoad() {
		final RootLayoutPanel rootLayoutPanel = RootLayoutPanel.get(); 
		rootLayoutPanel.add(new HTML("Loading..."));
		UserServiceAsync.INSTANCE.fetchLoggedInUserInfo(new CommonAsyncCallback<InitialData>() {

			@Override
			public void onSuccess(InitialData initialData) {
				loggedInUserFullName = initialData.getLoggedInUserFullName();
				loggedInUserId = initialData.getLoggedInUserId(); 
				rootLayoutPanel.clear(); 
				rootLayoutPanel.add(new MainScreen(initialData));
			}});
	}

}
